﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Last03.Aqiantai
{
    /// <summary>
    /// Tuifang.xaml 的交互逻辑
    /// </summary>
    public partial class Tuifang : Page
    {
        public Tuifang()
        {
            InitializeComponent();
        }

        HotelEntities context = new HotelEntities();

        private void TextBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            this.txtsfzh.Text = "";
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {//查询已入住客人信息
            ShowRuzhu();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {//删除，即退房客人
            string sql = "delete from Ruzhu where 客人身份证号={0}";
            int i = context.Database.ExecuteSqlCommand(sql, txtsfzh.Text);
            if (i < 0)
            {
                MessageBox.Show("请重新输入正确格式的身份证号！");
            }
            ShowRuzhu();
        }

        private void ShowRuzhu()
        {
            var q = context.Database.SqlQuery<Ruzhu>("select * from Ruzhu");
            this.dataGrid.ItemsSource = q.ToList();
        }

        
    }
}
